avatar

目录
Jupyter correct workflow

https://samedwardes.com/blog/2022-10-23-best-jupyter-lab-install/ reference

Jupyter Basic Environment Creation and Customization

Part 1: Making a Python Kernel Available in Jupyter (Installed via pipx)

  1. Install Jupyter via pipx (Already done):

    bash
    1
    2
    pipx install jupyter --include-deps
    pipx ensurepath

    alternative:
    pipx install pretzelai
    pipx ensurepath

  2. Set Up a Python Virtual Environment for the Kernel:

    bash
    1
    python3.12 -m venv ~/venvs/python3.12
  3. Activate the Virtual Environment:

    bash
    1
    source ~/venvs/python3.12/bin/activate
  4. Install ipykernel in the Virtual Environment:

    bash
    1
    pip install ipykernel
  5. Add the Kernel to Jupyter:

    bash
    1
    python -m ipykernel install --user --name python3.12 --display-name "Python 3.12"
  6. Deactivate the Virtual Environment:

    bash
    1
    deactivate

Part 2: Customizing JupyterLab for a Better Workflow (With pipx)

1. Install JupyterLab Extensions with Pipx

bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
pipx install jupyter --include-deps
pipx ensurepath
pipx runpip jupyter install jupyterlab-code-formatter
pipx runpip jupyter install black
pipx runpip jupyter install jupyterlab-lsp
pipx runpip jupyter install python-lsp-server[all]
pipx runpip jupyter install lckr-jupyterlab-variableinspector
pipx runpip jupyter install jupyterlab-spellchecker
pipx runpip jupyter install jupyter-ai[all]
pipx runpip jupyter install jupyter_ai_magics
pipx runpip jupyter install mitoinstaller
pipx runpip jupyter install jupyterlab-snippets

pipx run jupyter lab build

Other Tips

in order to use %%ai magic command, you will need to install in separate kernel this:
pip install jupyter_ai_magics

another option is to manually install JupyAI

also codeium auto code completion is availabe from codeium

jupyterlab-mutableai can change jupyter code to production code

install jupyterlab-execute-time which can show execution time

in view tab, check the line number

jupyterlabcodetoc can be useful

Pretzel Commands

bash
1
2
3
4
5
6
7
pipx runpip pretzelai install jupyter
pipx runpip pretzelai install jupyterlab-code-formatter
pipx runpip pretzelai install jupyterlab-lsp
pipx runpip pretzelai install python-lsp-server[all]
pipx runpip pretzelai install black
pipx runpip pretzelai install lckr-jupyterlab-variableinspector
pipx run jupyter lab build

2. Using the Built-in Terminal and File Explorer

JupyterLab comes with built-in support for a terminal and file explorer, allowing you to manage files and run shell commands directly within the interface.

  • Open a terminal: Go to File > New > Terminal to open a terminal inside JupyterLab.
  • Use the file explorer: The file browser on the left sidebar can be used to open, move, rename, or delete files directly within the JupyterLab environment.

Important Notes:

  • Rebuild JupyterLab after installing extensions:
    bash
    1
    pipx run jupyter lab build
  • Verify extensions:
    bash
    1
    pipx run jupyter labextension list

    3. Enable an Extension

    bash
    1
    pipx run jupyter labextension enable @jupyterlab/notebook-extension:language-server

disable:

bash
1
pipx run jupyter labextension disable @jupyterlab/notebook-extension:language-server

Jupyter Kernel Management

Kernel Specification (kernelspec) System

Kernel Spec Locations

Check kernel spec locations:

bash
1
jupyter kernelspec list

How Kernels Are Registered

bash
1
python -m ipykernel install --user --name mypython --display-name "Python 3.12"

Remove an Old Kernel

bash
1
jupyter kernelspec uninstall old-env

Example: Adding Python 3.12 as a Kernel to Pipx Jupyter

  1. Create a Virtual Environment for Python 3.12:

    bash
    1
    python3.12 -m venv ~/venvs/python3.12
  2. Activate the Environment:

    bash
    1
    source ~/venvs/python3.12/bin/activate
  3. Install ipykernel in the Environment:

    bash
    1
    pip install ipykernel
  4. Add the Kernel to Jupyter:

    bash
    1
    python -m ipykernel install --user --name python3.12 --display-name "Python 3.12"

评论